Socket
Socket
Sign inDemoInstall

html2canvas

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html2canvas

Screenshots with JavaScript


Version published
Maintainers
1
Created

What is html2canvas?

The html2canvas npm package is a JavaScript library that allows you to take screenshots of web pages or parts of them directly in the browser. It captures the content of HTML elements as a canvas image.

What are html2canvas's main functionalities?

Screenshot of the entire page or specific elements

This code takes a screenshot of the entire body of the webpage and appends the resulting canvas to the body. You can replace `document.body` with any other element to capture a specific part of the page.

html2canvas(document.body).then(function(canvas) {
  document.body.appendChild(canvas);
});

Configuration options for the screenshot

This code demonstrates how to pass configuration options to html2canvas. Options such as `onclone`, `width`, and `height` can be used to customize the screenshot process.

html2canvas(element, {
  onclone: function(clonedDoc) {},
  width: 800,
  height: 600
}).then(function(canvas) {
  document.body.appendChild(canvas);
});

Saving the canvas as an image

After capturing the screenshot, this code converts the canvas to a PNG image and triggers a download of the image file.

html2canvas(element).then(function(canvas) {
  var img = canvas.toDataURL('image/png');
  var link = document.createElement('a');
  link.href = img;
  link.download = 'screenshot.png';
  link.click();
});

Other packages similar to html2canvas

FAQs

Package last updated on 22 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc